package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "gitee.com/general252/kingbase.com/gokb"
)

const (
	host     = "192.168.88.88"
	port     = 54321
	user     = "system"
	password = "123456"
	dbname   = "test"
)

func main() {
	connInfo := fmt.Sprintf("host=%s port=%d user=%s "+
		"password=%s dbname=%s sslmode=disable",
		host, port, user, password, dbname)

	db, err := sql.Open("kingbase", connInfo)
	if err != nil {
		panic(err)
	}

	if err = db.Ping(); err != nil {
		panic(err)
	}

	fmt.Println("Connection test success!")

	rows, err := db.Query("SELECT tablename FROM pg_tables WHERE schemaname = 'public'")
	if err != nil {
		log.Println(err)
		return
	}
	defer rows.Close()

	for rows.Next() {
		var tableName string
		if err = rows.Scan(&tableName); err != nil {
			log.Println(err)
		} else {
			log.Println(tableName)
		}
	}

	_ = db.Close()
}
